<?php


namespace App\Models\Bus;

use App\Models\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Bus extends Model
{
    protected $table = 'akbus_bus';

    protected $fillable = [
        'batch',
        'brand',
        'model',
        'engine_num',
        'frame_nun',
        'license_plate_num',
        'original',
        'discount',
        'net_worth',
        'old_license_plate_num',
        'issue_at',
        'max_num',
        'start_use_at',
        'length',
        'voucher',
        'type',
        'note',
        'start_at',
        'register_at',
        'insurance_start_at',
        'insurance_end_at',
        'maintenance_at',
        'cylinder_annual_inspection_at',
        'technical_assessment_at',
        'vehicle_travel_license_url',
        'invoice_url',
        'sign_certificate_url',
        'qualified_certificate_url',
        'is_check',
    ];

    /**
     * 不可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [
    ];

    /**
     * 类型转化
     *
     * @var array
     */
    protected $casts = [
    ];

    /**
     * 隐藏的字段
     *
     * @var array
     */
    protected $hidden = [
    ];

    /**
     * 拼接车牌号字符
     *
     * @param  string  $value
     *
     * @return string
     */
    public function getLicensePlateNumAttribute($value): string
    {
        return '陕G'.$value;
    }

    /**
     * 拼接旧车牌号字符
     *
     * @param  string  $value
     *
     * @return string
     */
    public function getOldLicensePlateNumAttribute($value): ?string
    {
        return $value ? '陕G'.$value : $value;
    }

    /**
     * 资质文件
     */
    public function qualificationFile(): HasMany
    {
        return $this->hasmany(BusQualificationFile::class, 'bus_id');
    }

    /**
     * 资质文件
     */
    public function isCheck(): HasMany
    {
        return $this->hasmany(BusIsCheck::class, 'bus_id');
    }
}
